home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PsL Monthly 1993 December
/
PSL Monthly Shareware CD-ROM (December 1993).iso
/
prgmming
/
dos
/
c
/
checktv.exe
/
CHECK.CPP
< prev
Wrap
C/C++ Source or Header
|
1992-10-09
|
2KB
|
105 lines
/*
* CHECK.CPP
*
* Ezra Shabi
* October 9, 1992
*
*/
#define Uses_TApplication
#define Uses_TKeys
#define Uses_TRect
#define Uses_TMenuBar
#define Uses_TSubMenu
#define Uses_TMenuItem
#define Uses_TStatusLine
#define Uses_TDeskTop
#include <string.h>
#include <tv.h>
const int cmCheckItem1 = 200; // new commands definitions
const int cmCheckItem2 = 201;
const char *Item1 = "[ ] Check item ~1~"; // check items names
const char *Item2 = "[ ] Check item ~2~";
int Flag1 = 1; // check items flags
int Flag2 = 0;
class TMyApp : public TApplication
{
public:
TMyApp();
static TMenuBar *initMenuBar( TRect r );
virtual void handleEvent( TEvent& event);
void SetCheckedItem(TMenuItem *item, int flag);
static TMenuItem *CheckMenuItem1, *CheckMenuItem2;
};
TMenuItem *TMyApp::CheckMenuItem1; // define check menu items
TMenuItem *TMyApp::CheckMenuItem2;
TMyApp::TMyApp() :
TProgInit(&TMyApp::initStatusLine,
&TMyApp::initMenuBar,
&TMyApp::initDeskTop)
{
SetCheckedItem(CheckMenuItem1, Flag1); // init check menu items
SetCheckedItem(CheckMenuItem2, Flag2);
}
TMenuBar *TMyApp::initMenuBar( TRect r )
{
r.b.y = r.a.y + 1;
// create check menu objects
CheckMenuItem1 = new TMenuItem(Item1, cmCheckItem1, kbNoKey);
CheckMenuItem2 = new TMenuItem(Item2, cmCheckItem2, kbNoKey);
return new TMenuBar( r, // create the menu bar
*new TSubMenu("~M~enu", kbAltM)+
*CheckMenuItem1+
*CheckMenuItem2+
newLine()+
*new TMenuItem("E~x~it", cmQuit, cmQuit, hcNoContext, "Alt-X" )
);
}
void TMyApp::handleEvent(TEvent& event)
{
TApplication::handleEvent(event);
if( event.what == evCommand ) {
switch( event.message.command ) {
case cmCheckItem1: // menu item 1
Flag1 = !Flag1;
SetCheckedItem(CheckMenuItem1, Flag1);
break;
case cmCheckItem2: // menu item 2
Flag2 = !Flag2;
SetCheckedItem(CheckMenuItem2, Flag2);
break;
default:
return;
}
clearEvent( event ); // clear event after handling
}
}
void TMyApp::SetCheckedItem(TMenuItem *item, int flag)
{
char far *cp;
cp = strchr(item->name, '[') + 1; // find the "[" char
*cp = (flag) ? 'X' : ' '; // and place ' ' or 'X'
return; // right after it.
}
int main()
{
TMyApp myApp;
myApp.run();
return 0;
}